package com.ruoyi.view.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.view.domain.WeatherStatistics;
import com.ruoyi.view.service.IWeatherStatisticsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * weather_statisticsController
 *
 * @author ruoyi
 * @date 2023-04-11
 */
@Controller
@RequestMapping("/view/weather_statistics")
public class WeatherStatisticsController extends BaseController
{
    private String prefix = "data-analysis/weather_statistics";

    @Autowired
    private IWeatherStatisticsService weatherStatisticsService;

    @RequiresPermissions("data-analysis:weather_statistics:view")
    @GetMapping()
    public String weather_statistics()
    {
        return prefix + "/weather_statistics";
    }

    /**
     * 查询weather_statistics列表
     */
//    @RequiresPermissions("data-analysis:weather_statistics:list")
    @CrossOrigin
    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(WeatherStatistics weatherStatistics)
    {
//        startPage();
        List<WeatherStatistics> list = weatherStatisticsService.selectWeatherStatisticsList(weatherStatistics);
        return getDataTable(list);
    }

    /**
     * 导出weather_statistics列表
     */
    @RequiresPermissions("data-analysis:weather_statistics:export")
    @Log(title = "weather_statistics", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WeatherStatistics weatherStatistics)
    {
        List<WeatherStatistics> list = weatherStatisticsService.selectWeatherStatisticsList(weatherStatistics);
        ExcelUtil<WeatherStatistics> util = new ExcelUtil<WeatherStatistics>(WeatherStatistics.class);
        return util.exportExcel(list, "weather_statistics数据");
    }

    /**
     * 新增weather_statistics
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存weather_statistics
     */
    @RequiresPermissions("data-analysis:weather_statistics:add")
    @Log(title = "weather_statistics", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WeatherStatistics weatherStatistics)
    {
        return toAjax(weatherStatisticsService.insertWeatherStatistics(weatherStatistics));
    }

    /**
     * 修改weather_statistics
     */
    @RequiresPermissions("data-analysis:weather_statistics:edit")
    @GetMapping("/edit/{weather}")
    public String edit(@PathVariable("weather") String weather, ModelMap mmap)
    {
        WeatherStatistics weatherStatistics = weatherStatisticsService.selectWeatherStatisticsByWeather(weather);
        mmap.put("weatherStatistics", weatherStatistics);
        return prefix + "/edit";
    }

    /**
     * 修改保存weather_statistics
     */
    @RequiresPermissions("data-analysis:weather_statistics:edit")
    @Log(title = "weather_statistics", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WeatherStatistics weatherStatistics)
    {
        return toAjax(weatherStatisticsService.updateWeatherStatistics(weatherStatistics));
    }

    /**
     * 删除weather_statistics
     */
    @RequiresPermissions("data-analysis:weather_statistics:remove")
    @Log(title = "weather_statistics", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(weatherStatisticsService.deleteWeatherStatisticsByWeathers(ids));
    }
}
